/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.sys.web;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.sys.entity.TbMpWalletStream;
import com.thinkgem.jeesite.modules.sys.entity.TbShopVerify;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.service.ShopAddService;
import com.thinkgem.jeesite.modules.sys.service.TbShopVerifyService;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 身份证审核Controller
 * @author huoyan403
 * @version 2016-10-29
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/tbShopVerify")
public class TbShopVerifyController extends BaseController {

	@Autowired
	private TbShopVerifyService tbShopVerifyService;
	
	@ModelAttribute
	public TbShopVerify get(@RequestParam(required=false) String id) {
		TbShopVerify entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbShopVerifyService.get(id);
		}
		if (entity == null){
			entity = new TbShopVerify();
		}
		return entity;
	}
	

	@RequestMapping(value = {"list", ""})
	public String list(TbShopVerify tbShopVerify, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbShopVerify> page = tbShopVerifyService.findPage(new Page<TbShopVerify>(request, response), tbShopVerify);
		model.addAttribute("page", page);
		if(page.getList().size()==0){
			model.addAttribute("message1","无查询结果");
		}
		return "modules/sys/tbShopVerifyList";
	}

	@RequestMapping(value = "form")
	public String form(TbShopVerify TbShopVerify, Model model) {
		model.addAttribute("TbShopVerify", TbShopVerify);
		return "modules/sys/tbShopVerifyForm";
	}


	@RequestMapping(value = "save")
	public String save(TbShopVerify TbShopVerify, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, TbShopVerify)){
			return form(TbShopVerify, model);
		}
		tbShopVerifyService.save(TbShopVerify);
		addMessage(redirectAttributes, "保存店铺审核成功");
		return "redirect:"+Global.getAdminPath()+"/sys/TbShopVerify/?repage";
	}

	@RequestMapping(value = "edit",method = RequestMethod.POST)
	@ResponseBody
	public TbShopVerify delete(TbShopVerify TbShopVerify,HttpServletRequest request) {
		String id = request.getParameter("id");
		String status = request.getParameter("auditorState");
		TbShopVerify.setId(id);
		TbShopVerify.setStatus(status);
		tbShopVerifyService.edit(TbShopVerify);
		return TbShopVerify;
	}
	@RequestMapping(value ="mpWalletStream")
	public String mpWalletStream(TbMpWalletStream tbMpWalletStream, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbMpWalletStream> page = tbShopVerifyService.mpWalletStream(new Page<TbMpWalletStream>(request, response), tbMpWalletStream);
		model.addAttribute("walletpage", page);
		return "modules/sys/shopMpWalletStream";
	}
}